<template>
<div>
    <h2>您的学生有：</h2>
        <table>
            <tr>
                <td>学生姓名</td>
                <td>操作</td>
            </tr>
            <tr v-for="i in items" :key="i.id">
                <td>{{i.name}}</td>
                <td @click="add(i.name)">加入班级</td>
            </tr>
        </table>
    </div>
</template>

<script>
import axios from "axios"
import {add_cate} from "../axios_api/api.js"
export default {
    name:"student",
    data() {
        return {
            items:"",
            cate:1
        }
    },
    methods:{
        get_student(){
            // var data = {"id":id}
            axios({
                url:"http://127.0.0.1:8000/app03/s/",
                method:"get",
                // params:data
            }).then(res=>{
                console.log(res.data)
                this.items = res.data.data
            })
        },
        add(name){
           var data={"name":name,
                    "cate":this.cate}
                add_cate(data).then(res=>{
                    console.log(res)
                    window.location.reload()
                })
        
        
        }      
    },
    created(){
        this.get_student()
    }
}
</script>

<style>

</style>
